﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
namespace KabiManagementWeb.Controllers
{
    public class TimeSlotController : Controller
    {
        KBManagementDataContext context = DBUtils.GetContext(DBUtils.DBType.Local);
        //
        // GET: /TimeSlor/

        public ActionResult Index()
        {
            return View(context.TimeSlots);
        }

       
        //
        // GET: /TimeSlor/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /TimeSlor/Create

        [HttpPost]
        public ActionResult Create(TimeSlot collection)
        {
            try
            {
                // TODO: Add insert logic here
                context.TimeSlots.InsertOnSubmit(collection);
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /TimeSlor/Edit/5
 
        public ActionResult Edit(int id)
        {
            var time = context.TimeSlots.Single(x => x.ID == id);
            return View(time);
        }

        //
        // POST: /TimeSlor/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, TimeSlot collection)
        {
            try
            {
                var time = context.TimeSlots.Single(x => x.ID == id);
                time.EndTime = collection.EndTime;
                time.StartTime = collection.StartTime;
                time.Ts_Name = collection.Ts_Name;
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /TimeSlor/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /TimeSlor/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
